package cn.yuanqiao.web.controller.archive.uploadfile;

import cn.yuanqiao.archive.uploadfile.dto.FileUploadDTO;
import cn.yuanqiao.archive.uploadfile.dto.FileUploadRequestDTO;
import cn.yuanqiao.archive.uploadfile.dto.ModelUploadDTO;
import cn.yuanqiao.archive.uploadfile.dto.PackageUploadDTO;
import cn.yuanqiao.archive.uploadfile.service.impl.FileService;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/archive/fileUpload")
public class FileController extends BaseController {
    @Autowired
    private FileService fileService;

    @PostMapping
    @Log(title = "挂接包上传", businessType = BusinessType.UPLOAD)
    public AjaxResult check(FileUploadRequestDTO param){
        String unZipCharSet = param.getUnZipCharSet();
        if(!StringUtils.isNotEmpty(unZipCharSet)){
            throw new ServiceException("解压编码不能为空");
        }
        FileUploadDTO fileUploadDTO = fileService.fileUpload(param);
        return success(fileUploadDTO);
    }


    @PostMapping("/model")
    @Log(title = "大事记/组织沿革模板上传", businessType = BusinessType.UPLOAD)
    public AjaxResult model(ModelUploadDTO param){
        FileUploadDTO fileUploadDTO = fileService.modelFileUpload(param);
        return success(fileUploadDTO);
    }

    @PostMapping("/oaPackage")
    @Log(title = "归档包上传", businessType = BusinessType.UPLOAD)
    public AjaxResult oaPackage(PackageUploadDTO param){
        FileUploadDTO fileUploadDTO = fileService.packageFileUpload(param);
        return success(fileUploadDTO);
    }
}
